/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.asseco.mio.search;

import com.asseco.mio.WorkPosition;
import com.asseco.persistence.service.HibernateUtil;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author gjoko.mitrovski
 */
public class SearchPrijaviOdjavi {

    public static boolean checkIfLast (WorkPosition workposition){
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        Criteria criteria = session.createCriteria(WorkPosition.class).add
                (Restrictions.like("employment", workposition.getEmployment())).addOrder
                (Order.desc("startDate"));
        List list = criteria.list();
        if (!list.isEmpty()){
            WorkPosition wps = (WorkPosition) list.get(0);
            if (wps.getId().equals(workposition.getId())){
                return true;
            }else{
                return false;
            }
        }else{
          return false;
        }

    }
}
